#version 120

attribute vec3 a_position;
attribute vec3 a_normal;

uniform bool enableLighting;
uniform vec3 ambientColor;
uniform vec3 directionalColor;
uniform vec3 lightingDirection;

uniform mat4 mvMatrix;
uniform mat4 projMatrix;
uniform mat4 normalMatrix;

varying vec3 lightWeighting;

void main(){

    if (!enableLighting){
        lightWeighting = vec3(1.0, 1.0, 1.0);
    } else {
        vec4 transformNormal = normalize(normalMatrix * vec4(a_normal, 0.0));
        float directionLightWeight = max(dot(transformNormal.xyz, lightingDirection), 0.0);
        lightWeighting = ambientColor + directionalColor * directionLightWeight;
    }

    gl_Position = projMatrix*mvMatrix*vec4(a_position, 1.0);
}
